import { searchFormProps } from "@/components/SearchForm/interface";
import dayjs from "dayjs";

/**
 * @param {Array} dataGrid 搜索的表格
 * @param {Ref} proTableBox 表格的ref
 * @param {string} queryField 搜索的字段(多个以逗号分隔)
 * @param {string} placeholder 提示站位符
 * @param {string} type input框类型
 * @description 自定义搜索条件
 */
export const useSearchForm = () => {
  const searchForm = reactive<searchFormProps>({
    form: {
      start: "",
      end: "",
      type: ""
    },
    options: [
      {
        type: "input",
        label: "关键值",
        first: true,
        hide: false
      },
      {
        type: "date_custom",
        label: "",
        prop: "start",
        attrs: {
          type: "date"
        },
        hide: false,
        defaultValue: dayjs().subtract(3, "month").format("YYYY-MM-DD")
      },
      {
        type: "date_custom",
        label: "",
        prop: "end",
        attrs: {
          type: "date"
        },
        hide: false,
        defaultValue: dayjs().format("YYYY-MM-DD")
      },
      {
        type: "select",
        label: "",
        prop: "type",
        hide: false,
        defaultValue: ""
      }
    ]
  });

  onBeforeMount(() => {
    setSingleDictionaries(searchForm, 3, "type");
  });

  return {
    searchForm
  };
};
